package com.bolt.admin.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2020/9/21.
 */
@Controller
public class ExceptionController implements ErrorController {

    @Autowired
    HttpServletRequest request;

    @Override
    @RequestMapping("/error")
    public String getErrorPath() {
        Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
        switch (statusCode) {
            case 404:
                return "/error/404";
            case 400:
                return "/error/400";
            case 403:
                return "/error/403";
            default:
                return "/error/500";
        }

    }
}

 